$(function(){
  
  $('.citySearch').click(function(){
        var cityname = $('input[name="citySearch"]').val();
        var sel = document.getElementById('citySelectList');
        var isMatch = 0;
        if(cityname.trim() == ''){
          $('#citySelectList option').show();
          return false;
        }
        $('#citySelectList option').each(function(){
          var city = $(this).text();
          var city_val = $(this).val();
          if(city.indexOf(cityname) == -1){
            $(this).hide();
          }else{
            $(this).show();
            if(!isMatch) $('#citySelectList').val(city_val);
            isMatch = 1;
          console.log($(this).text());
          }
      });
      if(!isMatch){
         $('#citySelectList option').eq(0).show();
         $('#citySelectList').val(0);
      }
      return false;

      });

    $('.shopSearch').click(function(){
      var shopname = $('input[name="searchName"]').val();
      var cityid  = $('#citySelectList_2').val()>0?$('#citySelectList_2').val()>0:258;
      $("#shop_list").html('<option value="0">不设置广告商家</option>');
      $.ajax({
        url:'/index.php?g=admin&m=activites&a=searchShop',
        type:"POST",
        data:{shopName:shopname,cityId:cityid},
        dataType:"JSON",
        success:function(data){
          console.log(data);
          if(data.shops.length>0) $("#shop_list").html('');
          $.each(data.shops,function(id,shop){
            var htm = '<option value="'+shop.shopId +'" data-manage-shopid="'+ shop.manageShopId +'">'+ shop.shopName+'(' + shop.branchName +')</option>';
            $('input[name="manageShopId"]').val(shop.manageShopId);
            $('input[name="shopName"]').val(shop.shopName+'(' + shop.branchName +')');
            $("#shop_list").append(htm);
            console.log(htm);
          });
        }});
      return false;
    });

  $('.hotShopSearch').click(function(){
    var cityid = $('#citySelectList').val();
    $.ajax({
      url:'/index.php?g=admin&m=activites&a=searchHotShops',
      type:'POST',
      data:{cityid:cityid},
      dataType:'JSON',
      success:function(data){
        console.log(data);
        $('.saveHotShop').show();
      }
    });
  });
});